﻿using Common;
using Common.DataModels;
using PLC.Domain.Models;

namespace PLC.Domain.Entity;
/// <summary>
/// 气密的返修数据
/// </summary>
public class RepairAirtightData:AggregateRoot
{
    /// <summary>
    /// 上端板条码
    /// </summary>
    public string UpperEndPlateCode { get;  set; }
    /// <summary>
    /// 下端板条码
    /// </summary>
    public string LowerEndPlateCode { get;  set; }
    /// <summary>
    /// 数据
    /// </summary>
    public string Data { get;  set; }
    /// <summary>
    /// 创建时间
    /// </summary>
    public DateTime CreateTime { get;  set; }
    /// <summary>
    /// 是否删除
    /// </summary>
    public bool IsDelete { get;  set; }
    public RepairAirtightData() { }

    public RepairAirtightData SetUpperEndPlateCode(string upperEndPlateCode)
    {
        this.UpperEndPlateCode = string.IsNullOrWhiteSpace(upperEndPlateCode) ? string.Empty : upperEndPlateCode;
        return this;
    }

    public RepairAirtightData SetLowerEndPlateCode(string lowerEndPlateCode)
    {
        this.LowerEndPlateCode = string.IsNullOrWhiteSpace(lowerEndPlateCode) ? string.Empty : lowerEndPlateCode;
        return this;
    }
    public RepairAirtightData SetData(IEnumerable<PLCDataModel>? data)
    {
        if (data == null || !data.Any())
        {
            this.Data = string.Empty;
        }

        this.Data = JsonHelper.SerializeObject(data);
        return this;
    }

    public RepairAirtightData Build()
    {
        base.Id = SnowflakeHelper.GetId();
        this.IsDelete = false;
        this.CreateTime = DateTime.Now;
        return this;
    }
}